// src/utils/avatar.js
import Men from "@/assets/avatar/TodayMen.jpg";
import AncientMen from "@/assets/avatar/AncientMen.jpg";
import ModernMen from "@/assets/avatar/ModernMen.jpg";
import Women from "@/assets/avatar/TodayWomen.jpg";
import AncientWoMen from "@/assets/avatar/AncientWoMen.jpg";
import ModernWoMen from "@/assets/avatar/ModernWoMen.jpg";
import unknown from "@/assets/avatar/unknown.png";

// 定义生产环境的静态URL路径
const PROD_URLS = {
  Men: '/static/uploads/image/TodayMen.jpg',
  AncientMen: '/static/uploads/image/AncientMen.jpg',
  ModernMen: '/static/uploads/image/ModernMen.jpg',
  Women: '/static/uploads/image/TodayWoMen.jpg',
  AncientWoMen: '/static/uploads/image/AncientWoMen.jpg',
  ModernWoMen: '/static/uploads/image/ModernWoMen.jpg',
  unknown: '/static/uploads/image/unknown.png'
};

// 判断是否为生产环境
const isProd = process.env.NODE_ENV === 'production';

/**
 * 获取默认头像
 * @param {Object} options
 * @param {number|string} options.gender 性别（1男，2女）
 * @param {string|number} options.birthDate 出生日期（可选）
 * @returns {string} 头像URL
 */
export function getDefaultAvatar({ gender = 2, birthDate } = {}) {
  let age = 0;
  let birth;
  if (birthDate) {
    birth = new Date(birthDate);
  } else {
    birth = new Date(); // 如果birthDate为空，默认当前时间
  }
  const now = new Date();
  age = now.getFullYear() - birth.getFullYear();
  
  // 根据环境选择使用本地导入的图片或静态URL
  if (gender == 1) {
    if (age < 100) return isProd ? PROD_URLS.Men : Men;
    if (age > 1000) return isProd ? PROD_URLS.AncientMen : AncientMen;
    return isProd ? PROD_URLS.ModernMen : ModernMen;
  } else if (gender == 2) {
    if (age < 100) return isProd ? PROD_URLS.Women : Women;
    if (age > 1000) return isProd ? PROD_URLS.AncientWoMen : AncientWoMen;
    return isProd ? PROD_URLS.ModernWoMen : ModernWoMen;
  }
  return isProd ? PROD_URLS.unknown : unknown;
}
